import axios from 'axios'
const host = process.env.NODE_ENV === 'development' ? '' : 'http://182.150.39.140:80'
class Axios {
  postAxiosData (data) {
    if (host) {
      data.url = data.url.replace(/^\/\w+/, '')
    }
    return axios({
      baseUrl: host,
      timeout: 60000,
      method: 'post',
      url: data.url,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      data: data.userMsg,
      transformRequest: [function (data) {
        let ret = []
        for (let it in data) {
          ret.push(encodeURIComponent(it) + '=' + encodeURIComponent(data[it]))
        }
        return ret.join('&')
      }]
    })
  }

  getAxiosData (data) {
    if (host) {
      data.url = data.url.replace(/^\\\w/g, '')
    }
    return axios({
      baseURL: host,
      timeout: 60000,
      method: 'get',
      url: data.url,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'},
      params: data.data
    })
  }
}

export default Axios
